home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dfpp01.zip / DFWINDOW.H < prev    next >
C/C++ Source or Header  |  1992-11-21  |  10KB  |  306 lines

  1. // ------------ dfwindow.h
  2.  
  3. #ifndef DFWINDOW_H
  4. #define DFWINDOW_H
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10.  
  11. #include "dflatdef.h"
  12. #include "rectangl.h"
  13. #include "strings.h"
  14.  
  15. // -------- window attribute flags
  16. const int MOVEABLE   = 0x0001;
  17. const int SIZEABLE   = 0x0002;
  18. const int BORDER     = 0x0004;
  19. const int TITLEBAR   = 0x0008;
  20. const int CONTROLBOX = 0x0010;
  21. const int MINBOX     = 0x0020;
  22. const int MAXBOX     = 0x0040;
  23. const int SHADOW     = 0x0080;
  24. const int SAVESELF   = 0x0100;
  25. const int NOCLIP     = 0x0200;
  26. const int MENUBAR    = 0x0400;
  27. const int STATUSBAR  = 0x0800;
  28. const int VSCROLLBAR = 0x1000;
  29. const int HSCROLLBAR = 0x2000;
  30. const int FRAMEWND   = 0x4000;
  31.  
  32. // --------------- Color Macros
  33. enum Colors {
  34.     BLACK,
  35.     BLUE,
  36.     GREEN,
  37.     CYAN,
  38.     RED,
  39.     MAGENTA,
  40.     BROWN,
  41.     LIGHTGRAY,
  42.     DARKGRAY,
  43.     LIGHTBLUE,
  44.     LIGHTGREEN,
  45.     LIGHTCYAN,
  46.     LIGHTRED,
  47.     LIGHTMAGENTA,
  48.     YELLOW,
  49.     WHITE
  50. };
  51.  
  52. // ------ window shadow attributes
  53. const unsigned char ShadowFG = DARKGRAY;
  54. const unsigned char ShadowBG = BLACK;
  55.  
  56. // ----- minimized icon dimensions
  57. const int IconWidth = 10;
  58. const int IconHeight = 3;
  59.  
  60. // --------------- border characters
  61. const unsigned char FOCUS_NW   = '\xc9';
  62. const unsigned char FOCUS_NE   = '\xbb';
  63. const unsigned char FOCUS_SE   = '\xbc';
  64. const unsigned char FOCUS_SW   = '\xc8';
  65. const unsigned char FOCUS_SIDE = '\xba';
  66. const unsigned char FOCUS_LINE = '\xcd';
  67. const unsigned char NW         = '\xda';
  68. const unsigned char NE         = '\xbf';
  69. const unsigned char SE         = '\xd9';
  70. const unsigned char SW         = '\xc0';
  71. const unsigned char SIDE       = '\xb3';
  72. const unsigned char LINE       = '\xc4';
  73.  
  74. // ----------------- title bar characters
  75. const unsigned char CONTROLBOXCHAR = '\xf0';
  76. const unsigned char MAXPOINTER     = 24;
  77. const unsigned char MINPOINTER     = 25;
  78. const unsigned char RESTOREPOINTER = 18;
  79.  
  80. // ----------- window states
  81. enum WndState     {
  82.     OPENING,
  83.     ISRESTORED,
  84.     ISMINIMIZED,
  85.     ISMAXIMIZED,
  86.     ISCLOSING,
  87.     CLOSED
  88. };
  89.  
  90. // ---------- window colors
  91. struct Color {
  92.     Colors fg, bg;      // standard colors
  93.     Colors sfg, sbg;    // selected text colors
  94.     Colors ffg, fbg;    // window frame colors
  95.     Colors hfg, hbg;    // highlighted text colors
  96. };
  97.  
  98. class Application;
  99. class StatusBar;
  100. class PopDown;
  101.  
  102. class DFWindow    {
  103. protected:
  104.     WndType windowtype;   // window type
  105.     int prevmouseline;    // holders for
  106.     int prevmousecol;     // mouse coordinates
  107. private:
  108.     String *title;              // window title
  109.     // -------------- window attributes
  110.     int restored_attrib;        // attributes when restored
  111.     Bool clipoverride;          // True to override clipping
  112.     Rect restored_rc;           // restored state rect
  113.     // ------- for painting overlapping windows
  114.     void PaintOverLappers();
  115.     // ----- control menu
  116.     PopDown *ctlmenu;
  117.     void OpenCtlMenu();
  118.     void DeleteCtlMenu();
  119.     // -------- for clearing the window
  120.     char clearch;
  121.     // --------- common window contructor code
  122.     void InitWindow(char *ttl,
  123.         int lf, int tp, int ht, int wd, DFWindow *par);
  124.     void InitWindow(int lf, int tp, int ht, int wd,
  125.         DFWindow *par);
  126.     virtual void SetColors();
  127.     void Enqueue();
  128.     void Dequeue();
  129.     Bool ClipParent(int &x, int y, String *ln);
  130.     void WriteChar(int ch, int x, int y,
  131.         Rect &rc, int fg, int bg);
  132.     void WriteString(String &ln, int x, int y,
  133.         Rect &rc, int fg, int bg);
  134.     Rect PositionIcon();
  135.     friend class StatusBar;
  136. protected:
  137.     // --------------- video memory save data
  138.     char *videosave;      // video save buffer
  139.     Bool visible;         // True = window has been shown
  140.     int attrib;           // Window attribute flags
  141.     Bool DblBorder;       // True = dbl border on focus
  142.     Color colors;         // window colors
  143.     WndState windowstate; // Restored, Maximized,
  144.                           // Minimized, Closing
  145.     Rect rect;            // window coordinates
  146.                           // (0/0 to 79/24)
  147.     // ------ previous capture focus handle
  148.     DFWindow *prevcapture;
  149.     // -------------- window geneology
  150.     DFWindow *parent;           // parent window
  151.     // -------- children
  152.     DFWindow *first;            // first child window
  153.     DFWindow *last;             // last child window
  154.     // -------- siblings
  155.     DFWindow *next;             // next sibling window
  156.     DFWindow *prev;             // previous sibling window
  157.     // -------- system-wide
  158.     void NextSiblingFocus();
  159.     void PrevSiblingFocus();
  160.     void WriteClientString(String &ln,int x,int y,int fg,int bg);
  161.     void WriteWindowString(String &ln,int x,int y,int fg,int bg);
  162.     void WriteWindowChar(int ch,int x,int y,int fg,int bg);
  163.     void WriteClientChar(int ch,int x,int y,int fg,int bg);
  164.     // ------------- client window coordinate adjustments
  165.     virtual void AdjustBorders();
  166.     int BorderAdj;              // adjust for border
  167.     int TopBorderAdj;           // adjust for top border
  168.     int BottomBorderAdj;        // adjust for bottom border
  169.     // -----
  170.     Bool HitControlBox(int x, int y)
  171.         { return (Bool)(x-Left() == 2 && y-Top() == 0 &&
  172.             (attrib & CONTROLBOX)); }
  173.     friend void DispatchEvents(Application *ApWnd);
  174.     friend DFWindow *MouseWindow();
  175.     friend DFWindow *inWindow(int x, int y, int &fg, int &bg);
  176. public:
  177.     // -------- constructors
  178.     DFWindow(char *ttl, int lf, int tp, int ht, int wd,
  179.                 DFWindow *par)
  180.         { InitWindow(ttl, lf, tp, ht, wd, par); }
  181.     DFWindow(char *ttl, int ht, int wd, DFWindow *par)
  182.         { InitWindow(ttl, -1, -1, ht, wd, par); }
  183.     DFWindow(int lf, int tp, int ht, int wd, DFWindow *par)
  184.         { InitWindow(lf, tp, ht, wd, par); }
  185.     DFWindow(int ht, int wd, DFWindow *par)
  186.         { InitWindow(-1, -1, ht, wd, par); }
  187.     DFWindow(char *ttl, DFWindow *par = NULL)
  188.         { InitWindow(ttl, 0, 0, -1, -1, par); }
  189.     // -------- destructor
  190.     virtual ~DFWindow()
  191.         { if (windowstate != CLOSED) CloseWindow(); }
  192.     // ------- window dimensions and position
  193.     Rect WindowRect()    { return rect; }
  194.     Rect ShadowedRect();
  195.     int Right()          { return rect.Right(); }
  196.     int Left()           { return rect.Left(); }
  197.     int Top()            { return rect.Top(); }
  198.     int Bottom()         { return rect.Bottom(); }
  199.     int Height()         { return Bottom() - Top() + 1; }
  200.     int Width()          { return Right() - Left() + 1; }
  201.     // ------ client space dimensions and position
  202.     Rect ClientRect();
  203.     int ClientRight()    { return Right()-BorderAdj; }
  204.     int ClientLeft()     { return Left()+BorderAdj; }
  205.     int ClientTop()      { return Top()+TopBorderAdj; }
  206.     int ClientBottom()   { return Bottom()-BottomBorderAdj; }
  207.     int ClientHeight()   { return Height()-TopBorderAdj-
  208.                               BottomBorderAdj; }
  209.     int ClientWidth()    { return Width()-BorderAdj*2; }
  210.  
  211.     DFWindow *Parent()   { return parent; }
  212.     DFWindow *First()    { return first; }
  213.     DFWindow *Last()     { return last; }
  214.     DFWindow *Next()     { return next; }
  215.     DFWindow *Prev()     { return prev; }
  216.  
  217.     Bool isVisible()     { return visible; }
  218.     int Attribute()      { return attrib; }
  219.     void SetAttribute(int atr)
  220.                          { attrib |= atr; AdjustBorders(); }
  221.     void ClearAttribute(int atr)
  222.                          { attrib &= ~atr; AdjustBorders(); }
  223.     WndType WindowType() { return windowtype; }
  224.     // ----- Control Menu messages
  225.     void CtlMenuMove();
  226.     void CtlMenuSize();
  227.     // -------- API messages
  228.     virtual void OpenWindow();
  229.     virtual void CloseWindow();
  230.     virtual void Show();
  231.     virtual void Hide();
  232.     virtual Bool SetFocus();
  233.     virtual void ResetFocus();
  234.     virtual void EnterFocus(DFWindow *child) {}
  235.     virtual void LeaveFocus(DFWindow *child) {}
  236.     void CaptureFocus();
  237.     void ReleaseFocus();
  238.     virtual void Paint();
  239.     virtual void Paint(Rect rc);
  240.     virtual void Border();
  241.     virtual void Shadow();
  242.     virtual void Title();
  243.     virtual void ClearWindow();
  244.     virtual void ShiftChanged(int sk);
  245.     virtual void Keyboard(int key);
  246.     virtual void KeyReleased() {}
  247.     virtual void DoubleClick(int mx, int my);
  248.     virtual void LeftButton(int mx, int my);
  249.     virtual void ButtonReleased(int mx, int my);
  250.     virtual void MouseMoved(int mx, int my) {}
  251.     virtual void Move(int x, int y);
  252.     virtual void Size(int x, int y);
  253.     virtual void ParentSized(int, int) {}
  254.     virtual void ClockTick() {}
  255.     void Minimize();
  256.     void Maximize();
  257.     void Restore();
  258.     WndState State() { return windowstate; }
  259.     Rect &VisibleRect();
  260.     Colors ClientFG()    { return colors.fg; }
  261.     Colors ClientBG()    { return colors.bg; }
  262.     Colors SelectedFG()  { return colors.sfg; }
  263.     Colors SelectedBG()  { return colors.sbg; }
  264.     Colors FrameFG()     { return colors.ffg; }
  265.     Colors FrameBG()     { return colors.fbg; }
  266.     Colors HighlightFG() { return colors.ffg; }
  267.     Colors HighlightBG() { return colors.fbg; }
  268.     void SetClearChar(char ch) { clearch = ch; }
  269. };
  270.  
  271. inline DFWindow *inWindow(int x, int y)
  272. {
  273.     int fg, bg;
  274.     return inWindow(x, y, fg, bg);
  275. }
  276.  
  277. inline void DFWindow::WriteClientString(String &ln,
  278.                     int x,int y,int fg,int bg)
  279. {
  280.     WriteString(ln,x+ClientLeft(),y+ClientTop(),
  281.         ClientRect(),fg,bg);
  282. }
  283.  
  284. inline void DFWindow::WriteWindowString(String &ln,
  285.                     int x,int y,int fg,int bg)
  286. {
  287.     WriteString(ln,x+Left(),y+Top(),
  288.         ShadowedRect(),fg,bg);
  289. }
  290.  
  291. inline void DFWindow::WriteWindowChar(int ch,int x,int y,int fg,int bg)
  292. {
  293.     WriteChar(ch, x+Left(), y+Top(),
  294.         ShadowedRect(), fg, bg);
  295. }
  296.  
  297. inline void DFWindow::WriteClientChar(int ch,int x,int y,int fg,int bg)
  298. {
  299.     WriteChar(ch, x+ClientLeft(),y+ClientTop(),
  300.         ClientRect(),fg,bg);
  301. }
  302.  
  303. #endif
  304.  
  305.  
  306.